import 'package:flutter/material.dart';
import '../pages/login_page.dart';
import '../pages/agreement_page.dart';
import '../pages/privacy_policy.dart';
import '../pages/home_page.dart';

/// 路由名称常量
class RouteNames {
  static const String login = '/login';
  static const String agreement = '/agreement';
  static const String privacyPolicy = '/privacy_policy';
  static const String home = '/home';
  static const String memo = '/memo';
}

/// 路由配置
class RouteConfiguration {
  /// 路由表
  static Map<String, WidgetBuilder> routes = {
    RouteNames.login: (context) => const LoginPage(),
    RouteNames.agreement: (context) => AgreementPage(
          title: ModalRoute.of(context)?.settings.arguments as String? ?? '用户协议',
        ),
    RouteNames.privacyPolicy: (context) => PrivacyPolicyPage(
          title: ModalRoute.of(context)?.settings.arguments as String? ?? '隐私政策',
        ),
    RouteNames.home: (context) => const HomePage(),
    
  };

  /// 统一的页面切换动画
  static Route<dynamic>? onGenerateRoute(RouteSettings settings) {
    final WidgetBuilder? builder = routes[settings.name];
    if (builder != null) {
      return PageRouteBuilder(
        settings: settings,
        pageBuilder: (context, animation, secondaryAnimation) => builder(context),
        transitionsBuilder: (context, animation, secondaryAnimation, child) {
          const begin = Offset(1.0, 0.0);
          const end = Offset.zero;
          const curve = Curves.easeInOut;
          var tween = Tween(begin: begin, end: end).chain(
            CurveTween(curve: curve),
          );
          var offsetAnimation = animation.drive(tween);
          return SlideTransition(
            position: offsetAnimation,
            child: child,
          );
        },
      );
    }
    return null;
  }
}
